package by.blog.web;

import by.blog.dao.beans.Film;
import by.blog.dao.dao.factory.MysqlDaoFactory;
import by.blog.service.CategoryService;
import by.blog.service.UserService;
import by.blog.service.beans.UIFilm;



/**
 *This class  communicates between the object and its representation in the form
 * Film to UIFilm(this is UI representation)
 */
public class Converter {

    MysqlDaoFactory mysqlDaoFactory;
    private CategoryService categoryService;
    private UserService userService;
    UIFilm uiFilm;

    public Converter() {
        mysqlDaoFactory = MysqlDaoFactory.getInstance();
        categoryService = new CategoryService();
        userService = new UserService();
    }

    public UIFilm convertFilmToUIFilm(Film film) {

        uiFilm = new UIFilm();

        uiFilm.setFilm_id(film.getFilm_id());
        uiFilm.setFilm_name(film.getFilm_name());
        uiFilm.setCategory(categoryService.readUnit(film.getCategory_id()).getCategory_name());
        uiFilm.setUser(userService.readUnit(film.getUser_name()).getUser_name());

        return uiFilm;
    }
}
